package com.easylinkin.linkappapi.meterbilling.config;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;
import site.morn.boot.web.Responses;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * class info :
 *
 * @author liuqihang
 * @date 2021/7/30 16:04
 */
@Component
public class WechatPublicAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException exception) throws IOException, ServletException {
        RestMessage message = RestBuilders.failureBuilder().code("login.failure")
                .message(exception.getMessage()).build();

        Responses.standard(httpServletResponse).respond(message);
    }
}
